package waimai;

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

/**
 * @author huangya
 * @date 2025/2/8
 */
public class T111 {

    public static void main(String[] args) throws Exception {
        // 创建URL对象
        URL url = new URL("http://127.0.0.1:13984/api/llm/v1/agent/invoke");

        // 打开连接
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        // 设置请求方式为POST
        connection.setRequestMethod("POST");

        // 设置允许输出和输入
        connection.setDoOutput(true);
        connection.setDoInput(true);

        // 设置请求头Content-Type为application/json
        connection.setRequestProperty("Content-Type", "application/json; utf-8");

        // 要发送的数据
        String bodyString = "{\"agent_id\":\"llm-avm-nlu\",\"agent_request\":{\"debug_mode\":false,\"debug\":false,\"query\":\"播放周杰伦的青花瓷\",\"proxy_token\":\"zebra-proxy-90fa8a5e5acfbdbe67d792fd6c4c70c7_pre\",\"vehicle_model\":\"990144\",\"llmProjectId\":\"normandy\",\"history\":[{\"role\":\"user\",\"qid\":\"699b0d7d22c848e29e63f6fc00c8a0ba\",\"content\":\"介绍一下三国演义\",\"timestamp\":1738921289563},{\"role\":\"assistant\",\"nlu\":{\"domain\":\"llm\",\"intent\":\"baike\"},\"qid\":\"699b0d7d22c848e29e63f6fc00c8a0ba\",\"content\":\"《三国演义》是中国四大名著之一，由元末明初的罗贯中创作。它以东汉末年黄巾起义为开端，以西晋建立为结尾，全面展现了三国时期的政治、军事、文化和社会等方面的丰富内容。小说以魏、蜀、吴三个政权为主线，讲述了三国之间的激烈矛盾与斗争，最终西晋实现了统一。作品不仅是一部历史小说，也是中国文学史上的重要经典。\",\"timestamp\":1738921289563}],\"rewritten_query\":\"播放周杰伦的青花瓷\",\"version\":\"1.0\",\"extend\":{\"is_first_round\":1,\"zid\":\"defaultZid\",\"device_token\":\"token-qa-e50867b1c9794777ae6af8f91d72ef6b\",\"proxy_token\":\"zebra-proxy-90fa8a5e5acfbdbe67d792fd6c4c70c7_pre\",\"asr_result\":{},\"project\":\"00\",\"session_id\":\"__G96635tk\",\"location\":{\"geo\":{\"level5\":\"\",\"level4\":\"\",\"level1\":\"\",\"level3\":\"\",\"level2\":\"\"},\"latitude\":0,\"longitude\":0},\"customizer\":{\"need_proxy_token\":false},\"skip_skyeye\":true,\"carModel\":\"990144\",\"ts\":{\"nluTs\":1738921290730,\"dmTs\":1738921290825,\"lastAudioTs\":1738921290730}},\"stream\":false,\"user_id\":\"llm-chain-monitor-benz_poc\",\"conversation_id\":\"mock_conversation_id\",\"nlu\":{\"domain\":\"entertainment\",\"intent\":\"Entertainment\"},\"vin\":\"VIN_LLM_MONITOR_0001\",\"_source\":{\"app_id\":\"llm-appkit-agent-multimedia\"},\"channel_id\":\"dd3ee5f0919545\",\"request_id\":\"72528bf006984a1fb6ed30ed4c0d1b90\",\"_target\":[{\"agent_env\":\"default\",\"app_id\":\"llm-avm-nlu\"}],\"timestamp\":1738921291060}}";

        try (OutputStream os = connection.getOutputStream()) {
            // 写入数据
            os.write(bodyString.getBytes(StandardCharsets.UTF_8));
        }

        // 发送请求
        int responseCode = connection.getResponseCode();
        System.out.println("Response Code : " + responseCode);

        // 读取响应
        // 注意：这里仅展示了如何获取响应码，读取响应体需要额外的代码

        // 关闭连接
        connection.disconnect();
    }

}
